<?php

namespace app\api\controller;

use app\admin\model\site\PlayProject;
use app\common\controller\Api;

use app\admin\model\user\Player as M_Player;
use app\common\library\token\driver\Redis;

/**
 * 会员接口
 */
class Player extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = '*';


    public function create(){
        $params = $this->getParams(M_Player::$allowField);
        $params['uid']=$this->uid();
        $result=M_Player::create($params);
        $this->success($result);
    }

    public function update(){
        $params = $this->getParams(M_Player::$allowField);
        $result=M_Player::update($params,['uid'=>$this->uid()]);
        $this->success('',$result);
    }

    public function list(){
        $params=$this->request->post();
        $list=(new M_Player())->getList($params);
        $this->success('',$list);
    }

    public function info(){
        $uid = $this->request->get('uid',$this->uid());
        $result= M_Player::get(['uid'=>$uid]);
        $result['projects']=PlayProject::whereIn('id',explode(',',$result->projects))->select();
        $result['user'] = \app\common\model\User::field('id,avatar,nickname')->where(['id'=>$uid])->find();
        $result['images'] = explode(',',$result['images']);
        $this->success('',$result);

    }

    public function online(){
        $redis = new \think\cache\driver\Redis();
        if($redis->get("PW:online:".$this->uid())){
            $redis->rm("PW:online:".$this->uid());
        }else{
            $redis->set("PW:online:".$this->uid(),1);
        }
        $this->success();
    }


}
